package baseweb.springbootweb.service.impl;

import baseweb.springbootweb.mapper.DeptMapper;
import baseweb.springbootweb.mapper.EmpMapper;
import baseweb.springbootweb.pojo.Emp;
import baseweb.springbootweb.pojo.Pagebean;
import baseweb.springbootweb.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceimpl implements EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Override
    public Pagebean page(Integer page, Integer pageSize,
                         String name, Short gender, LocalDate begin, LocalDate end) {
        PageHelper.startPage(page, pageSize);
        List<Emp> emplist= empMapper.list(name,gender,begin, end);
        Page<Emp> p= (Page<Emp>) emplist;

        Pagebean pagebean=new Pagebean(p.getTotal(),p.getResult());
        return pagebean;
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Override
    public void save(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp getid(Integer id) {
        return empMapper.get(id);
    }


    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }
}
